import request from '@/config/axios'

export interface BookPageCreateReqVO {
  bookId: number
  pageNumber: number
  imageUrl?: string
  imageWidth?: number
  imageHeight?: number
  textContent?: string
  chineseTranslation?: string
  textLanguage?: string
  officialAudioUrl?: string
  audioDuration?: number
  readingDifficulty?: string
  keyWords?: string[]
}

export interface BookPageUpdateReqVO extends BookPageCreateReqVO {
  id: number
}

export interface BookPageAdminRespVO {
  id: number
  bookId: number
  pageNumber: number
  imageUrl?: string
  imageWidth?: number
  imageHeight?: number
  textContent?: string
  chineseTranslation?: string
  textLanguage?: string
  officialAudioUrl?: string
  audioDuration?: number
  readingDifficulty?: string
  keyWords?: string[]
  createTime: string
  updateTime: string
  creator?: string
  updater?: string
}

export interface BookPagePageReqVO extends PageParam {
  bookId?: number
  pageNumber?: number
  textKeyword?: string
}

// 创建绘本页面
export const createBookPage = (data: BookPageCreateReqVO) => {
  return request.post({
    url: '/reading/admin/pages/create',
    data
  })
}

// 更新绘本页面
export const updateBookPage = (data: BookPageUpdateReqVO) => {
  return request.put({
    url: '/reading/admin/pages/update',
    data
  })
}

// 删除绘本页面
export const deleteBookPage = (id: number) => {
  return request.delete({
    url: '/reading/admin/pages/delete',
    params: { id }
  })
}

// 获取绘本页面详情
export const getBookPage = (id: number) => {
  return request.get({
    url: '/reading/admin/pages/get',
    params: { id }
  })
}

// 获取绘本页面分页
export const getBookPagePage = (params: BookPagePageReqVO) => {
  return request.get({
    url: '/reading/admin/pages/page',
    params
  })
}

// 根据绘本ID获取页面列表
export const getBookPagesByBookId = (bookId: number) => {
  return request.get({
    url: '/reading/admin/pages/list-by-book',
    params: { bookId }
  })
}

// 批量创建绘本页面
export const batchCreateBookPages = (data: BookPageCreateReqVO[]) => {
  return request.post({
    url: '/reading/admin/pages/batch-create',
    data
  })
}

// 获取下一个页面ID
export const getNextBookPageId = () => {
  return request.get({
    url: '/reading/admin/pages/next-id'
  })
}
